
MD5_CMD = md5sum

USR_MD5_FILE	    = check_usr.md5
WEB_MD5_FILE	    = check_web.md5
ifeq ($(YDT_BOX_ENABLE), true)
YDT_BOX_MD5_FILE    = check_ydt_box.md5
endif

# HI3521 don't have slave chip related images
USR_IMAGES_NEED_VERIFY	    = $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME)
WEB_IMAGES_NEED_VERIFY	    = $(OUTPUT_HB_BK)/$(WEB_CRAMFS_NAME)
ifeq ($(YDT_BOX_ENABLE), true)
YDT_BOX_IMAGES_NEED_VERIFY	= $(OUTPUT_HB_BK)/$(YDT_BOX_CRAMFS_NAME)
endif

$(OUTPUT_HB_BK)/$(USR_MD5_FILE): $(USR_IMAGES_NEED_VERIFY)
	$(PUSHD) $(OUTPUT_HB_BK); \
	$(MD5_CMD) $(USR_CRAMFS_NAME) > $(USR_MD5_FILE); \
	$(POPD);
	
$(OUTPUT_HB_BK)/$(WEB_MD5_FILE): $(WEB_IMAGES_NEED_VERIFY)
	$(PUSHD) $(OUTPUT_HB_BK); \
	$(MD5_CMD) $(WEB_CRAMFS_NAME) > $(WEB_MD5_FILE); \
	$(POPD);

ifeq ($(YDT_BOX_ENABLE), true)
$(OUTPUT_HB_BK)/$(YDT_BOX_MD5_FILE): $(YDT_BOX_IMAGES_NEED_VERIFY)
	$(PUSHD) $(OUTPUT_HB_BK); \
	$(MD5_CMD) $(YDT_BOX_CRAMFS_NAME) > $(YDT_BOX_MD5_FILE); \
	$(POPD);
endif

USR_HBGK_NAME_DEP = $(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME) $(OUTPUT_HB_BK)/$(WEB_CRAMFS_NAME) $(OUTPUT_HB_BK)/$(USR_MD5_FILE) $(OUTPUT_HB_BK)/$(WEB_MD5_FILE)
ifeq ($(YDT_BOX_ENABLE), true)
USR_HBGK_NAME_DEP += $(OUTPUT_HB_BK)/$(YDT_BOX_CRAMFS_NAME) $(OUTPUT_HB_BK)/$(YDT_BOX_MD5_FILE)
endif

USR_HBGK_YAFFS2_NAME = usr.hbgk.yaffs2
CFG_HBGK_YAFFS2_NAME = cfg.hbgk.yaffs2
BAK_HBGK_YAFFS2_NAME = backup.hbgk.yaffs2

usr.hbgk.bin: $(USR_HBGK_NAME_DEP)
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_EXTRACT) -p $(RM_PT_YAFFS2) -n hb0 -l $(shell basename $(OUTPUT_HB_BK))
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

lang.hbgk.bin: $(GUI_LANG_TAR)
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_EXTRACT) -p $(RM_PT_YAFFS2) -n hb1 -l $(shell basename $(OUTPUT_CFG))/logo/$(GUI_LANG_TAR_NAME)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

ifeq ($(BUILD_MINI_UBOOT), true)
mini_boot.hbgk.bin: mini_uboot.bin key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n mini-boot -l mini_uboot.bin -t $(RM_FLT_NAND) 0x0 0x20000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

UBOOT_HBGK_OFT = 0x20000
UBOOT_HBGK_SZE = 0x3E0000
else
UBOOT_HBGK_OFT = 0x0
UBOOT_HBGK_SZE = 0x400000
endif

uboot.hbgk.bin: uboot.bin key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n m-boot -l uboot.bin -t $(RM_FLT_NAND) $(UBOOT_HBGK_OFT) $(UBOOT_HBGK_SZE)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

env.hbgk.bin: env.bin key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n env -l env.bin -t $(RM_FLT_NAND) 0x400000 0x300000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

logo.hbgk.bin: logo.jpg key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n logo -l logo.jpg -t $(RM_FLT_NAND) 0x700000	0x300000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

kernel.hbgk.bin: uImage key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n kernel -l uImage -t $(RM_FLT_NAND) 0xA00000	0x600000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

root.hbgk.bin: root.hbgk.cramfs key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_CRAMFS) -n rootfs -l root.hbgk.cramfs -t $(RM_FLT_NAND) 0x1000000 0x600000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
	
ifeq ($(DUAL_CORE_CPU_MODE), true)
USR0_HBGK_OFT = 0x2800000
USR0_HBGK_SZE = 0x2000000
USR1_HBGK_OFT = 0x4800000
USR1_HBGK_SZE = 0x3000000

slave_arm_uboot.hbgk.bin: slave-arm-uboot.bin key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n rootfs -l slave-arm-uboot.bin -t $(RM_FLT_NAND) 0x1600000 0x300000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
	
slave_arm_kernel.hbgk.bin: slave-arm-kernel.bin key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n rootfs -l slave-arm-kernel.bin -t $(RM_FLT_NAND) 0x1900000 0x600000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@

slave_arm_root.hbgk.bin: slave-arm-rootfs.cramfs.initrd.img key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_BIN) -n rootfs -l slave-arm-rootfs.cramfs.initrd.img -t $(RM_FLT_NAND) 0x1F00000 0x900000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
else
USR0_HBGK_OFT = 0x1600000
USR0_HBGK_SZE = 0x2000000
USR1_HBGK_OFT = 0x3600000
USR1_HBGK_SZE = 0x4200000
endif

usr0.hbgk.bin: $(USR_HBGK_YAFFS2_NAME) key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n hb0 -l $(USR_HBGK_YAFFS2_NAME) -t $(RM_FLT_NAND) $(USR0_HBGK_OFT) $(USR0_HBGK_SZE)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n hb0 -l $(USR_HBGK_YAFFS2_NAME)_$(YAFFS2_SEC_EXT_NAME) -t $(RM_FLT_NAND) $(USR0_HBGK_OFT) $(USR0_HBGK_SZE)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@_$(YAFFS2_SEC_EXT_NAME)
endif

usr1.hbgk.bin: $(CFG_HBGK_YAFFS2_NAME) key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n hb1 -l $(CFG_HBGK_YAFFS2_NAME) -t $(RM_FLT_NAND) $(USR1_HBGK_OFT) $(USR1_HBGK_SZE)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n hb1 -l $(CFG_HBGK_YAFFS2_NAME)_$(YAFFS2_SEC_EXT_NAME) -t $(RM_FLT_NAND) $(USR1_HBGK_OFT) $(USR1_HBGK_SZE)
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@_$(YAFFS2_SEC_EXT_NAME)
endif

backup.hbgk.bin: $(BAK_HBGK_YAFFS2_NAME) key
	@$(ECHO) [$@] Changed file:$?
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n backup -l $(BAK_HBGK_YAFFS2_NAME) -t $(RM_FLT_NAND) 0x7800000 0x800000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(UPGRADE_MAKER) -f $(RM_FT_ERASURE) -p $(RM_PT_YAFFS2) -n backup -l $(BAK_HBGK_YAFFS2_NAME)_$(YAFFS2_SEC_EXT_NAME) -t $(RM_FLT_NAND) 0x7800000 0x800000
	mv $(UPGRADE_MAKER_OUTPUT_NAME) $@_$(YAFFS2_SEC_EXT_NAME)
endif

YAFFS2_PAGE_SIZE	= 1 # Use 2K byte page size
ifeq ($(PLATFORM), HI3535)
YAFFS2_ECC_TYPE		= 2 # 3535 use 4bits ecc
else
ifeq ($(PLATFORM), HI3536)
YAFFS2_ECC_TYPE		= 2 # 3536 use 4bits ecc
else
ifeq ($(PLATFORM), HI3520D_V300)
YAFFS2_ECC_TYPE		= 4 # HI3520D_V300 use 24bits ecc
else
ifeq ($(PLATFORM), HI3521A)
YAFFS2_ECC_TYPE		= 4 # HI3521A use 24bits ecc
else
ifeq ($(PLATFORM), HI3531A)
YAFFS2_ECC_TYPE		= 2 # 3536 use 4bits ecc
else
YAFFS2_ECC_TYPE		= 1 # Other use 1bit ecc
endif
endif
endif
endif
endif

ifeq ($(SEC_YAFFS2_ENABLE), true)
YAFFS2_ECC_TYPE_SEC	= 4 # use 24bits ecc
endif

$(USR_HBGK_YAFFS2_NAME): $(USR_HBGK_NAME_DEP)
	@$(ECHO) [$@] Changed file:$?
	$(MK_YAFFS2) $(OUTPUT_HB_BK) $@ $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE)
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(MK_YAFFS2) $(OUTPUT_HB_BK) $@_$(YAFFS2_SEC_EXT_NAME) $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE_SEC)
endif

$(CFG_HBGK_YAFFS2_NAME): $(CFG_DIR_NAME)/logo/key $(GUI_LANG_TAR) $(shell find $(OUTPUT_CFG) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MK_YAFFS2) $(CFG_DIR_NAME) $@ $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE)
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(MK_YAFFS2) $(CFG_DIR_NAME) $@_$(YAFFS2_SEC_EXT_NAME) $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE_SEC)
endif

$(BAK_HBGK_YAFFS2_NAME): $(shell find $(BAK_DIR_NAME) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MK_YAFFS2) $(BAK_DIR_NAME) $@ $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE)
ifeq ($(SEC_YAFFS2_ENABLE), true)
	$(MK_YAFFS2) $(BAK_DIR_NAME) $@_$(YAFFS2_SEC_EXT_NAME) $(YAFFS2_PAGE_SIZE) $(YAFFS2_ECC_TYPE_SEC)
endif

$(OUTPUT_HB_BK)/$(USR_CRAMFS_NAME): $(shell find $(OUTPUT_USR_FS) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MKDIR) -p  $(OUTPUT_HB_BK)/
	$(MK_CRAMFS) $(OUTPUT_USR_FS) $@

$(OUTPUT_HB_BK)/$(WEB_CRAMFS_NAME): $(shell find $(OUTPUT_WEB_FS) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MKDIR) -p  $(OUTPUT_HB_BK)/
	$(WEB_JS_COMPRESS_SH)
	$(MK_CRAMFS) $(OUTPUT_WEB_FS) $@

ifeq ($(YDT_BOX_ENABLE), true)
$(OUTPUT_HB_BK)/$(YDT_BOX_CRAMFS_NAME): $(shell find $(OUTPUT_YDT_BOX_FS) 2>/dev/null)
	@$(ECHO) [$@] Changed file:$?
	$(MKDIR) -p  $(OUTPUT_HB_BK)/
	$(MK_CRAMFS) $(OUTPUT_YDT_BOX_FS) $@
endif

# vim:noet:sw=4:ts=4

